{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "connect ok!\n"
     ]
    }
   ],
   "source": [
    "from pprint import pprint\n",
    "import pickle\n",
    "import re\n",
    "from utils import *\n",
    "import time#计时模块\n",
    "from tqdm import tqdm\n",
    "from neo4j import GraphDatabase\n",
    "# 连接数据库\n",
    "driver = GraphDatabase.driver(\"bolt://localhost:7687\")\n",
    "print('connect ok!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('corpus/task6ckbqa_dev_2019.questions','r',encoding='utf-8').readlines()\n",
    "men2ent_dic = get_mention2entity_list()\n",
    "predata = {}\n",
    "for i in range(len(f)):\n",
    "    predata[i]={}\n",
    "    predata[i]['question']=f[i].split(':',1)[1].rstrip('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "def template_no1():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"(.*学)出[过|了]哪些(.*)？\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group(1),match_obj.group(2))\n",
    "            e1 = match_obj.group(1)\n",
    "            m2 = match_obj.group(2)\n",
    "            for one_mention in men2ent_dic[m2]:\n",
    "                if one_mention[1] == '1' or '0':\n",
    "                    e2 = one_mention[0]\n",
    "                    break\n",
    "            print(i,e1,e2)\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = 'match (a:Entity)<-[r1:Relation]-(b:Entity)-[r2:Relation]-(c:Entity) where a.name=$name and r1.name = $name2 and c.name=$name3 return b.name'\n",
    "            result = session.run(cql,name='<'+e1+'>',name2='<毕业院校>',name3='<'+e2+'>')\n",
    "            for x in result:\n",
    "                print(x['b.name'])\n",
    "                result_dict[i].append(x['b.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "def template_no2():\n",
    "    #解决“出了哪些”的问题\n",
    "#     template = \"(.*有多少家.*)|(.*有哪几家.*)\" 10 \"(.*什么学历.*)\" 7 \"(.*期货交易所.*)\" 2类\n",
    "    template =\"([0-9]+)的(.*)是.*\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group(1),match_obj.group(2))\n",
    "            e1 = match_obj.group(1)\n",
    "            m2 = match_obj.group(2)\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = 'match (a:Entity)-[r1:Relation]-(b:Entity)-[r2:Relation]-(c:Entity) where a.name=$name and r1.name = $name2 and r2.name=~\".*'+m2[:2]+'.*\" return c.name'\n",
    "            result = session.run(cql,name='<'+e1+'>',name2='<股票代码>')\n",
    "            for x in result:\n",
    "                print(x['c.name'])\n",
    "                result_dict[i].append(x['c.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "def template_no3():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"([^的]*).*董事长.*什么学历.*\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group(1))\n",
    "            e1 = match_obj.group(1)\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = 'match (a:Entity)-[r1:Relation]-(b:Entity)-[r2:Relation]-(c:Entity) where a.name=$name and r1.name = $name2 and r2.name=$name3 return c.name'\n",
    "            result = session.run(cql,name='<'+e1+'>',name2='<董事长>',name3='<学历>')\n",
    "            for x in result:\n",
    "                print(x['c.name'])\n",
    "                result_dict[i].append(x['c.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "def template_no4():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"位于(..)的期货交易所.*\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group(1))\n",
    "            e1 = match_obj.group(1)\n",
    "            ##############\n",
    "            if e1=='上海':\n",
    "                e1='魔都'\n",
    "            ##############\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = 'match (a:Entity)-[r1:Relation]-(b:Entity) where a.name=$name and r1.name = $name2 return b.name'\n",
    "            result = session.run(cql,name='<'+e1+'>',name2='<期货交易所>')\n",
    "            for x in result:\n",
    "                print(x['b.name'])\n",
    "                result_dict[i].append(x['b.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "def template_no5():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"(.*)有.*期货交易所.*\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group(1))\n",
    "            e1 = match_obj.group(1)\n",
    "            ##############\n",
    "            if e1=='国内'or e1=='中国':\n",
    "                session = driver.session()\n",
    "                cql = 'match (a:Entity)<-[r1:Relation]-(b:Entity) where a.name=\"<期货交易所>\" and r1.name = \"<类别>\" return b.name'\n",
    "                result = session.run(cql)\n",
    "                for x in result:\n",
    "                    print(x['b.name'])\n",
    "                    result_dict[i].append(x['b.name'])\n",
    "                count+=1\n",
    "            else:   \n",
    "                ##############\n",
    "                #查询库\n",
    "                session = driver.session()\n",
    "                cql = \"match (a:Entity)-[b:Relation]-(c:Entity)-[d:Relation]-(e:Entity)\\\n",
    "                            where a.name='<期货交易所>' and b.name='<类别>'and d.name='<位置>'and e.name=$name return c.name\"\n",
    "                                \n",
    "                result = session.run(cql,name='<'+e1+'>')\n",
    "                for x in result:\n",
    "                    print(x['c.name'])\n",
    "                    result_dict[i].append(x['c.name'])\n",
    "\n",
    "                count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "679 郑商所上市的农产品期货有什么\n",
      "<棉纱>\n",
      "<苹果>\n",
      "<棉花>\n",
      "<菜籽油>\n",
      "<油菜籽>\n",
      "<强麦>\n",
      "<普麦>\n",
      "<晚籼稻>\n",
      "<白糖>\n",
      "<粳稻>\n",
      "<早籼稻>\n",
      "<菜籽粕>\n",
      "680 郑商所上市的非农产品期货有什么\n",
      "<硅铁>\n",
      "<动力煤>\n",
      "<甲醇>\n",
      "<玻璃>\n",
      "<PTA>\n",
      "<锰硅>\n",
      "681 上海期货交易所上市的期货品种中金属期货有什么\n",
      "<镍>\n",
      "<镍>\n",
      "<铜>\n",
      "<铜>\n",
      "<黄金>\n",
      "<锌>\n",
      "<锌>\n",
      "<锡>\n",
      "<锡>\n",
      "<铝>\n",
      "<铝>\n",
      "<螺纹钢>\n",
      "<螺纹钢>\n",
      "<热轧卷板>\n",
      "<铅>\n",
      "<铅>\n",
      "<线材>\n",
      "<线材>\n",
      "<白银>\n",
      "682 上海期货交易所上市的期货品种中能源化工期货有什么\n",
      "<天然橡胶>\n",
      "<燃料油>\n",
      "<沥青>\n",
      "<沥青>\n",
      "<纸浆>\n",
      "<原油>\n",
      "683 上海期货交易所上市的期货品种中衍生品期货有什么\n",
      "<铜期权>\n",
      "<天胶期权>\n",
      "此类问题所占比例为：0.6527415143603134 5/766\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{0: [],\n",
       " 1: [],\n",
       " 2: [],\n",
       " 3: [],\n",
       " 4: [],\n",
       " 5: [],\n",
       " 6: [],\n",
       " 7: [],\n",
       " 8: [],\n",
       " 9: [],\n",
       " 10: [],\n",
       " 11: [],\n",
       " 12: [],\n",
       " 13: [],\n",
       " 14: [],\n",
       " 15: [],\n",
       " 16: [],\n",
       " 17: [],\n",
       " 18: [],\n",
       " 19: [],\n",
       " 20: [],\n",
       " 21: [],\n",
       " 22: [],\n",
       " 23: [],\n",
       " 24: [],\n",
       " 25: [],\n",
       " 26: [],\n",
       " 27: [],\n",
       " 28: [],\n",
       " 29: [],\n",
       " 30: [],\n",
       " 31: [],\n",
       " 32: [],\n",
       " 33: [],\n",
       " 34: [],\n",
       " 35: [],\n",
       " 36: [],\n",
       " 37: [],\n",
       " 38: [],\n",
       " 39: [],\n",
       " 40: [],\n",
       " 41: [],\n",
       " 42: [],\n",
       " 43: [],\n",
       " 44: [],\n",
       " 45: [],\n",
       " 46: [],\n",
       " 47: [],\n",
       " 48: [],\n",
       " 49: [],\n",
       " 50: [],\n",
       " 51: [],\n",
       " 52: [],\n",
       " 53: [],\n",
       " 54: [],\n",
       " 55: [],\n",
       " 56: [],\n",
       " 57: [],\n",
       " 58: [],\n",
       " 59: [],\n",
       " 60: [],\n",
       " 61: [],\n",
       " 62: [],\n",
       " 63: [],\n",
       " 64: [],\n",
       " 65: [],\n",
       " 66: [],\n",
       " 67: [],\n",
       " 68: [],\n",
       " 69: [],\n",
       " 70: [],\n",
       " 71: [],\n",
       " 72: [],\n",
       " 73: [],\n",
       " 74: [],\n",
       " 75: [],\n",
       " 76: [],\n",
       " 77: [],\n",
       " 78: [],\n",
       " 79: [],\n",
       " 80: [],\n",
       " 81: [],\n",
       " 82: [],\n",
       " 83: [],\n",
       " 84: [],\n",
       " 85: [],\n",
       " 86: [],\n",
       " 87: [],\n",
       " 88: [],\n",
       " 89: [],\n",
       " 90: [],\n",
       " 91: [],\n",
       " 92: [],\n",
       " 93: [],\n",
       " 94: [],\n",
       " 95: [],\n",
       " 96: [],\n",
       " 97: [],\n",
       " 98: [],\n",
       " 99: [],\n",
       " 100: [],\n",
       " 101: [],\n",
       " 102: [],\n",
       " 103: [],\n",
       " 104: [],\n",
       " 105: [],\n",
       " 106: [],\n",
       " 107: [],\n",
       " 108: [],\n",
       " 109: [],\n",
       " 110: [],\n",
       " 111: [],\n",
       " 112: [],\n",
       " 113: [],\n",
       " 114: [],\n",
       " 115: [],\n",
       " 116: [],\n",
       " 117: [],\n",
       " 118: [],\n",
       " 119: [],\n",
       " 120: [],\n",
       " 121: [],\n",
       " 122: [],\n",
       " 123: [],\n",
       " 124: [],\n",
       " 125: [],\n",
       " 126: [],\n",
       " 127: [],\n",
       " 128: [],\n",
       " 129: [],\n",
       " 130: [],\n",
       " 131: [],\n",
       " 132: [],\n",
       " 133: [],\n",
       " 134: [],\n",
       " 135: [],\n",
       " 136: [],\n",
       " 137: [],\n",
       " 138: [],\n",
       " 139: [],\n",
       " 140: [],\n",
       " 141: [],\n",
       " 142: [],\n",
       " 143: [],\n",
       " 144: [],\n",
       " 145: [],\n",
       " 146: [],\n",
       " 147: [],\n",
       " 148: [],\n",
       " 149: [],\n",
       " 150: [],\n",
       " 151: [],\n",
       " 152: [],\n",
       " 153: [],\n",
       " 154: [],\n",
       " 155: [],\n",
       " 156: [],\n",
       " 157: [],\n",
       " 158: [],\n",
       " 159: [],\n",
       " 160: [],\n",
       " 161: [],\n",
       " 162: [],\n",
       " 163: [],\n",
       " 164: [],\n",
       " 165: [],\n",
       " 166: [],\n",
       " 167: [],\n",
       " 168: [],\n",
       " 169: [],\n",
       " 170: [],\n",
       " 171: [],\n",
       " 172: [],\n",
       " 173: [],\n",
       " 174: [],\n",
       " 175: [],\n",
       " 176: [],\n",
       " 177: [],\n",
       " 178: [],\n",
       " 179: [],\n",
       " 180: [],\n",
       " 181: [],\n",
       " 182: [],\n",
       " 183: [],\n",
       " 184: [],\n",
       " 185: [],\n",
       " 186: [],\n",
       " 187: [],\n",
       " 188: [],\n",
       " 189: [],\n",
       " 190: [],\n",
       " 191: [],\n",
       " 192: [],\n",
       " 193: [],\n",
       " 194: [],\n",
       " 195: [],\n",
       " 196: [],\n",
       " 197: [],\n",
       " 198: [],\n",
       " 199: [],\n",
       " 200: [],\n",
       " 201: [],\n",
       " 202: [],\n",
       " 203: [],\n",
       " 204: [],\n",
       " 205: [],\n",
       " 206: [],\n",
       " 207: [],\n",
       " 208: [],\n",
       " 209: [],\n",
       " 210: [],\n",
       " 211: [],\n",
       " 212: [],\n",
       " 213: [],\n",
       " 214: [],\n",
       " 215: [],\n",
       " 216: [],\n",
       " 217: [],\n",
       " 218: [],\n",
       " 219: [],\n",
       " 220: [],\n",
       " 221: [],\n",
       " 222: [],\n",
       " 223: [],\n",
       " 224: [],\n",
       " 225: [],\n",
       " 226: [],\n",
       " 227: [],\n",
       " 228: [],\n",
       " 229: [],\n",
       " 230: [],\n",
       " 231: [],\n",
       " 232: [],\n",
       " 233: [],\n",
       " 234: [],\n",
       " 235: [],\n",
       " 236: [],\n",
       " 237: [],\n",
       " 238: [],\n",
       " 239: [],\n",
       " 240: [],\n",
       " 241: [],\n",
       " 242: [],\n",
       " 243: [],\n",
       " 244: [],\n",
       " 245: [],\n",
       " 246: [],\n",
       " 247: [],\n",
       " 248: [],\n",
       " 249: [],\n",
       " 250: [],\n",
       " 251: [],\n",
       " 252: [],\n",
       " 253: [],\n",
       " 254: [],\n",
       " 255: [],\n",
       " 256: [],\n",
       " 257: [],\n",
       " 258: [],\n",
       " 259: [],\n",
       " 260: [],\n",
       " 261: [],\n",
       " 262: [],\n",
       " 263: [],\n",
       " 264: [],\n",
       " 265: [],\n",
       " 266: [],\n",
       " 267: [],\n",
       " 268: [],\n",
       " 269: [],\n",
       " 270: [],\n",
       " 271: [],\n",
       " 272: [],\n",
       " 273: [],\n",
       " 274: [],\n",
       " 275: [],\n",
       " 276: [],\n",
       " 277: [],\n",
       " 278: [],\n",
       " 279: [],\n",
       " 280: [],\n",
       " 281: [],\n",
       " 282: [],\n",
       " 283: [],\n",
       " 284: [],\n",
       " 285: [],\n",
       " 286: [],\n",
       " 287: [],\n",
       " 288: [],\n",
       " 289: [],\n",
       " 290: [],\n",
       " 291: [],\n",
       " 292: [],\n",
       " 293: [],\n",
       " 294: [],\n",
       " 295: [],\n",
       " 296: [],\n",
       " 297: [],\n",
       " 298: [],\n",
       " 299: [],\n",
       " 300: [],\n",
       " 301: [],\n",
       " 302: [],\n",
       " 303: [],\n",
       " 304: [],\n",
       " 305: [],\n",
       " 306: [],\n",
       " 307: [],\n",
       " 308: [],\n",
       " 309: [],\n",
       " 310: [],\n",
       " 311: [],\n",
       " 312: [],\n",
       " 313: [],\n",
       " 314: [],\n",
       " 315: [],\n",
       " 316: [],\n",
       " 317: [],\n",
       " 318: [],\n",
       " 319: [],\n",
       " 320: [],\n",
       " 321: [],\n",
       " 322: [],\n",
       " 323: [],\n",
       " 324: [],\n",
       " 325: [],\n",
       " 326: [],\n",
       " 327: [],\n",
       " 328: [],\n",
       " 329: [],\n",
       " 330: [],\n",
       " 331: [],\n",
       " 332: [],\n",
       " 333: [],\n",
       " 334: [],\n",
       " 335: [],\n",
       " 336: [],\n",
       " 337: [],\n",
       " 338: [],\n",
       " 339: [],\n",
       " 340: [],\n",
       " 341: [],\n",
       " 342: [],\n",
       " 343: [],\n",
       " 344: [],\n",
       " 345: [],\n",
       " 346: [],\n",
       " 347: [],\n",
       " 348: [],\n",
       " 349: [],\n",
       " 350: [],\n",
       " 351: [],\n",
       " 352: [],\n",
       " 353: [],\n",
       " 354: [],\n",
       " 355: [],\n",
       " 356: [],\n",
       " 357: [],\n",
       " 358: [],\n",
       " 359: [],\n",
       " 360: [],\n",
       " 361: [],\n",
       " 362: [],\n",
       " 363: [],\n",
       " 364: [],\n",
       " 365: [],\n",
       " 366: [],\n",
       " 367: [],\n",
       " 368: [],\n",
       " 369: [],\n",
       " 370: [],\n",
       " 371: [],\n",
       " 372: [],\n",
       " 373: [],\n",
       " 374: [],\n",
       " 375: [],\n",
       " 376: [],\n",
       " 377: [],\n",
       " 378: [],\n",
       " 379: [],\n",
       " 380: [],\n",
       " 381: [],\n",
       " 382: [],\n",
       " 383: [],\n",
       " 384: [],\n",
       " 385: [],\n",
       " 386: [],\n",
       " 387: [],\n",
       " 388: [],\n",
       " 389: [],\n",
       " 390: [],\n",
       " 391: [],\n",
       " 392: [],\n",
       " 393: [],\n",
       " 394: [],\n",
       " 395: [],\n",
       " 396: [],\n",
       " 397: [],\n",
       " 398: [],\n",
       " 399: [],\n",
       " 400: [],\n",
       " 401: [],\n",
       " 402: [],\n",
       " 403: [],\n",
       " 404: [],\n",
       " 405: [],\n",
       " 406: [],\n",
       " 407: [],\n",
       " 408: [],\n",
       " 409: [],\n",
       " 410: [],\n",
       " 411: [],\n",
       " 412: [],\n",
       " 413: [],\n",
       " 414: [],\n",
       " 415: [],\n",
       " 416: [],\n",
       " 417: [],\n",
       " 418: [],\n",
       " 419: [],\n",
       " 420: [],\n",
       " 421: [],\n",
       " 422: [],\n",
       " 423: [],\n",
       " 424: [],\n",
       " 425: [],\n",
       " 426: [],\n",
       " 427: [],\n",
       " 428: [],\n",
       " 429: [],\n",
       " 430: [],\n",
       " 431: [],\n",
       " 432: [],\n",
       " 433: [],\n",
       " 434: [],\n",
       " 435: [],\n",
       " 436: [],\n",
       " 437: [],\n",
       " 438: [],\n",
       " 439: [],\n",
       " 440: [],\n",
       " 441: [],\n",
       " 442: [],\n",
       " 443: [],\n",
       " 444: [],\n",
       " 445: [],\n",
       " 446: [],\n",
       " 447: [],\n",
       " 448: [],\n",
       " 449: [],\n",
       " 450: [],\n",
       " 451: [],\n",
       " 452: [],\n",
       " 453: [],\n",
       " 454: [],\n",
       " 455: [],\n",
       " 456: [],\n",
       " 457: [],\n",
       " 458: [],\n",
       " 459: [],\n",
       " 460: [],\n",
       " 461: [],\n",
       " 462: [],\n",
       " 463: [],\n",
       " 464: [],\n",
       " 465: [],\n",
       " 466: [],\n",
       " 467: [],\n",
       " 468: [],\n",
       " 469: [],\n",
       " 470: [],\n",
       " 471: [],\n",
       " 472: [],\n",
       " 473: [],\n",
       " 474: [],\n",
       " 475: [],\n",
       " 476: [],\n",
       " 477: [],\n",
       " 478: [],\n",
       " 479: [],\n",
       " 480: [],\n",
       " 481: [],\n",
       " 482: [],\n",
       " 483: [],\n",
       " 484: [],\n",
       " 485: [],\n",
       " 486: [],\n",
       " 487: [],\n",
       " 488: [],\n",
       " 489: [],\n",
       " 490: [],\n",
       " 491: [],\n",
       " 492: [],\n",
       " 493: [],\n",
       " 494: [],\n",
       " 495: [],\n",
       " 496: [],\n",
       " 497: [],\n",
       " 498: [],\n",
       " 499: [],\n",
       " 500: [],\n",
       " 501: [],\n",
       " 502: [],\n",
       " 503: [],\n",
       " 504: [],\n",
       " 505: [],\n",
       " 506: [],\n",
       " 507: [],\n",
       " 508: [],\n",
       " 509: [],\n",
       " 510: [],\n",
       " 511: [],\n",
       " 512: [],\n",
       " 513: [],\n",
       " 514: [],\n",
       " 515: [],\n",
       " 516: [],\n",
       " 517: [],\n",
       " 518: [],\n",
       " 519: [],\n",
       " 520: [],\n",
       " 521: [],\n",
       " 522: [],\n",
       " 523: [],\n",
       " 524: [],\n",
       " 525: [],\n",
       " 526: [],\n",
       " 527: [],\n",
       " 528: [],\n",
       " 529: [],\n",
       " 530: [],\n",
       " 531: [],\n",
       " 532: [],\n",
       " 533: [],\n",
       " 534: [],\n",
       " 535: [],\n",
       " 536: [],\n",
       " 537: [],\n",
       " 538: [],\n",
       " 539: [],\n",
       " 540: [],\n",
       " 541: [],\n",
       " 542: [],\n",
       " 543: [],\n",
       " 544: [],\n",
       " 545: [],\n",
       " 546: [],\n",
       " 547: [],\n",
       " 548: [],\n",
       " 549: [],\n",
       " 550: [],\n",
       " 551: [],\n",
       " 552: [],\n",
       " 553: [],\n",
       " 554: [],\n",
       " 555: [],\n",
       " 556: [],\n",
       " 557: [],\n",
       " 558: [],\n",
       " 559: [],\n",
       " 560: [],\n",
       " 561: [],\n",
       " 562: [],\n",
       " 563: [],\n",
       " 564: [],\n",
       " 565: [],\n",
       " 566: [],\n",
       " 567: [],\n",
       " 568: [],\n",
       " 569: [],\n",
       " 570: [],\n",
       " 571: [],\n",
       " 572: [],\n",
       " 573: [],\n",
       " 574: [],\n",
       " 575: [],\n",
       " 576: [],\n",
       " 577: [],\n",
       " 578: [],\n",
       " 579: [],\n",
       " 580: [],\n",
       " 581: [],\n",
       " 582: [],\n",
       " 583: [],\n",
       " 584: [],\n",
       " 585: [],\n",
       " 586: [],\n",
       " 587: [],\n",
       " 588: [],\n",
       " 589: [],\n",
       " 590: [],\n",
       " 591: [],\n",
       " 592: [],\n",
       " 593: [],\n",
       " 594: [],\n",
       " 595: [],\n",
       " 596: [],\n",
       " 597: [],\n",
       " 598: [],\n",
       " 599: [],\n",
       " 600: [],\n",
       " 601: [],\n",
       " 602: [],\n",
       " 603: [],\n",
       " 604: [],\n",
       " 605: [],\n",
       " 606: [],\n",
       " 607: [],\n",
       " 608: [],\n",
       " 609: [],\n",
       " 610: [],\n",
       " 611: [],\n",
       " 612: [],\n",
       " 613: [],\n",
       " 614: [],\n",
       " 615: [],\n",
       " 616: [],\n",
       " 617: [],\n",
       " 618: [],\n",
       " 619: [],\n",
       " 620: [],\n",
       " 621: [],\n",
       " 622: [],\n",
       " 623: [],\n",
       " 624: [],\n",
       " 625: [],\n",
       " 626: [],\n",
       " 627: [],\n",
       " 628: [],\n",
       " 629: [],\n",
       " 630: [],\n",
       " 631: [],\n",
       " 632: [],\n",
       " 633: [],\n",
       " 634: [],\n",
       " 635: [],\n",
       " 636: [],\n",
       " 637: [],\n",
       " 638: [],\n",
       " 639: [],\n",
       " 640: [],\n",
       " 641: [],\n",
       " 642: [],\n",
       " 643: [],\n",
       " 644: [],\n",
       " 645: [],\n",
       " 646: [],\n",
       " 647: [],\n",
       " 648: [],\n",
       " 649: [],\n",
       " 650: [],\n",
       " 651: [],\n",
       " 652: [],\n",
       " 653: [],\n",
       " 654: [],\n",
       " 655: [],\n",
       " 656: [],\n",
       " 657: [],\n",
       " 658: [],\n",
       " 659: [],\n",
       " 660: [],\n",
       " 661: [],\n",
       " 662: [],\n",
       " 663: [],\n",
       " 664: [],\n",
       " 665: [],\n",
       " 666: [],\n",
       " 667: [],\n",
       " 668: [],\n",
       " 669: [],\n",
       " 670: [],\n",
       " 671: [],\n",
       " 672: [],\n",
       " 673: [],\n",
       " 674: [],\n",
       " 675: [],\n",
       " 676: [],\n",
       " 677: [],\n",
       " 678: [],\n",
       " 679: ['<棉纱>',\n",
       "  '<苹果>',\n",
       "  '<棉花>',\n",
       "  '<菜籽油>',\n",
       "  '<油菜籽>',\n",
       "  '<强麦>',\n",
       "  '<普麦>',\n",
       "  '<晚籼稻>',\n",
       "  '<白糖>',\n",
       "  '<粳稻>',\n",
       "  '<早籼稻>',\n",
       "  '<菜籽粕>'],\n",
       " 680: ['<硅铁>', '<动力煤>', '<甲醇>', '<玻璃>', '<PTA>', '<锰硅>'],\n",
       " 681: ['<镍>',\n",
       "  '<镍>',\n",
       "  '<铜>',\n",
       "  '<铜>',\n",
       "  '<黄金>',\n",
       "  '<锌>',\n",
       "  '<锌>',\n",
       "  '<锡>',\n",
       "  '<锡>',\n",
       "  '<铝>',\n",
       "  '<铝>',\n",
       "  '<螺纹钢>',\n",
       "  '<螺纹钢>',\n",
       "  '<热轧卷板>',\n",
       "  '<铅>',\n",
       "  '<铅>',\n",
       "  '<线材>',\n",
       "  '<线材>',\n",
       "  '<白银>'],\n",
       " 682: ['<天然橡胶>', '<燃料油>', '<沥青>', '<沥青>', '<纸浆>', '<原油>'],\n",
       " 683: ['<铜期权>', '<天胶期权>'],\n",
       " 684: [],\n",
       " 685: [],\n",
       " 686: [],\n",
       " 687: [],\n",
       " 688: [],\n",
       " 689: [],\n",
       " 690: [],\n",
       " 691: [],\n",
       " 692: [],\n",
       " 693: [],\n",
       " 694: [],\n",
       " 695: [],\n",
       " 696: [],\n",
       " 697: [],\n",
       " 698: [],\n",
       " 699: [],\n",
       " 700: [],\n",
       " 701: [],\n",
       " 702: [],\n",
       " 703: [],\n",
       " 704: [],\n",
       " 705: [],\n",
       " 706: [],\n",
       " 707: [],\n",
       " 708: [],\n",
       " 709: [],\n",
       " 710: [],\n",
       " 711: [],\n",
       " 712: [],\n",
       " 713: [],\n",
       " 714: [],\n",
       " 715: [],\n",
       " 716: [],\n",
       " 717: [],\n",
       " 718: [],\n",
       " 719: [],\n",
       " 720: [],\n",
       " 721: [],\n",
       " 722: [],\n",
       " 723: [],\n",
       " 724: [],\n",
       " 725: [],\n",
       " 726: [],\n",
       " 727: [],\n",
       " 728: [],\n",
       " 729: [],\n",
       " 730: [],\n",
       " 731: [],\n",
       " 732: [],\n",
       " 733: [],\n",
       " 734: [],\n",
       " 735: [],\n",
       " 736: [],\n",
       " 737: [],\n",
       " 738: [],\n",
       " 739: [],\n",
       " 740: [],\n",
       " 741: [],\n",
       " 742: [],\n",
       " 743: [],\n",
       " 744: [],\n",
       " 745: [],\n",
       " 746: [],\n",
       " 747: [],\n",
       " 748: [],\n",
       " 749: [],\n",
       " 750: [],\n",
       " 751: [],\n",
       " 752: [],\n",
       " 753: [],\n",
       " 754: [],\n",
       " 755: [],\n",
       " 756: [],\n",
       " 757: [],\n",
       " 758: [],\n",
       " 759: [],\n",
       " 760: [],\n",
       " 761: [],\n",
       " 762: [],\n",
       " 763: [],\n",
       " 764: [],\n",
       " 765: []}"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def template_no6():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"(.*)上市的(期货品种中)?(.*)有什么\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group())\n",
    "            e1 = match_obj.group(1)\n",
    "            e2 = match_obj.group(3)\n",
    "\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = \"match (a:Entity)-[b:Relation]-(c:Entity)-[d:Relation]-(e:Entity)\\\n",
    "                        where a.name=$name and d.name='<类别>'and e.name=$name1 return c.name\"\n",
    "\n",
    "            result = session.run(cql,name='<'+e1+'>',name1='<'+e2+'>')\n",
    "            for x in result:\n",
    "                print(x['c.name'])\n",
    "                result_dict[i].append(x['c.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict\n",
    "template_no6()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "#该模板不准确！\n",
    "def template_no7():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"(.+)的全称(是什么)?.*\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group().lower())\n",
    "            e1 = match_obj.group(1).lower()\n",
    "\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = \"match (a:Entity)-[b:Relation]-(c:Entity) \\\n",
    "                        where a.name=$name and b.name=~'.*[缩|简|称].*'  return c.name\"\n",
    "\n",
    "            result = session.run(cql,name='<'+e1+'>')\n",
    "            for x in result:\n",
    "                print(x['c.name'])\n",
    "                result_dict[i].append(x['c.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "#该模板不准确！\n",
    "def template_no8():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"([^的]+)(的)?股票代码.*\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group().lower())\n",
    "            e1 = match_obj.group(1).lower()\n",
    "\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = \"match (a:Entity)-[b:Relation]-(c:Entity) \\\n",
    "                        where a.name=$name and b.name='<股票代码>'  return c.name\"\n",
    "\n",
    "            result = session.run(cql,name='<'+e1+'>')\n",
    "            for x in result:\n",
    "                print(x['c.name'])\n",
    "                result_dict[i].append(x['c.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 写了八个模板"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "216 北京大学出了哪些作家？\n",
      "220 哈佛大学出了哪些物理学家？\n",
      "229 \"现代遗传学之父\"出生在哪个国家？\n",
      "248 清华大学出了哪些化学家？\n",
      "252 重庆大学出过哪些企业家？\n",
      "256 北京大学出了哪些天文学家？\n",
      "266 历史上西南联大培养了哪些科学家？\n",
      "287 我国在明朝时都有哪些著名的外交家？\n",
      "291 浙江大学出了哪些科学家？\n",
      "294 北京大学出了哪些科学家？\n",
      "296 武汉大学出了哪些天文学家？\n",
      "298 北京大学出了哪些经济学家？\n",
      "305 吉林大学出过哪些科学家？\n",
      "326 武汉大学出了哪些企业家？\n",
      "329 清华大学出了哪些哲学家？\n",
      "335 英国有哪些著名的数学家？\n",
      "336 清华大学出了哪些天文学家？\n",
      "345 北京大学出了哪些物理学家？\n",
      "346 北京大学出了哪些思想家？\n",
      "357 四川大学出了哪些作家？\n",
      "372 四川大学出了哪些企业家？\n",
      "383 北京大学出了哪些生物学家？\n",
      "395 东南大学出过哪些数学家？\n",
      "397 吉林大学出过哪些企业家？\n",
      "429 恒生电子的兄弟企业有哪几家？\n",
      "643 江苏省的上市公司一共有多少家？\n",
      "698 与海通证券董事长关联的公司有几家？\n",
      "712 在国内和香港都已上市的保险公司有哪几家？\n",
      "724 《三个音乐家》的作者是什么派别的画家？\n",
      "746 计算机的发明者，被称为计算机之父的是哪位科学家？\n",
      "此类问题所占比例为：3.91644908616188 30/766\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{0: [],\n",
       " 1: [],\n",
       " 2: [],\n",
       " 3: [],\n",
       " 4: [],\n",
       " 5: [],\n",
       " 6: [],\n",
       " 7: [],\n",
       " 8: [],\n",
       " 9: [],\n",
       " 10: [],\n",
       " 11: [],\n",
       " 12: [],\n",
       " 13: [],\n",
       " 14: [],\n",
       " 15: [],\n",
       " 16: [],\n",
       " 17: [],\n",
       " 18: [],\n",
       " 19: [],\n",
       " 20: [],\n",
       " 21: [],\n",
       " 22: [],\n",
       " 23: [],\n",
       " 24: [],\n",
       " 25: [],\n",
       " 26: [],\n",
       " 27: [],\n",
       " 28: [],\n",
       " 29: [],\n",
       " 30: [],\n",
       " 31: [],\n",
       " 32: [],\n",
       " 33: [],\n",
       " 34: [],\n",
       " 35: [],\n",
       " 36: [],\n",
       " 37: [],\n",
       " 38: [],\n",
       " 39: [],\n",
       " 40: [],\n",
       " 41: [],\n",
       " 42: [],\n",
       " 43: [],\n",
       " 44: [],\n",
       " 45: [],\n",
       " 46: [],\n",
       " 47: [],\n",
       " 48: [],\n",
       " 49: [],\n",
       " 50: [],\n",
       " 51: [],\n",
       " 52: [],\n",
       " 53: [],\n",
       " 54: [],\n",
       " 55: [],\n",
       " 56: [],\n",
       " 57: [],\n",
       " 58: [],\n",
       " 59: [],\n",
       " 60: [],\n",
       " 61: [],\n",
       " 62: [],\n",
       " 63: [],\n",
       " 64: [],\n",
       " 65: [],\n",
       " 66: [],\n",
       " 67: [],\n",
       " 68: [],\n",
       " 69: [],\n",
       " 70: [],\n",
       " 71: [],\n",
       " 72: [],\n",
       " 73: [],\n",
       " 74: [],\n",
       " 75: [],\n",
       " 76: [],\n",
       " 77: [],\n",
       " 78: [],\n",
       " 79: [],\n",
       " 80: [],\n",
       " 81: [],\n",
       " 82: [],\n",
       " 83: [],\n",
       " 84: [],\n",
       " 85: [],\n",
       " 86: [],\n",
       " 87: [],\n",
       " 88: [],\n",
       " 89: [],\n",
       " 90: [],\n",
       " 91: [],\n",
       " 92: [],\n",
       " 93: [],\n",
       " 94: [],\n",
       " 95: [],\n",
       " 96: [],\n",
       " 97: [],\n",
       " 98: [],\n",
       " 99: [],\n",
       " 100: [],\n",
       " 101: [],\n",
       " 102: [],\n",
       " 103: [],\n",
       " 104: [],\n",
       " 105: [],\n",
       " 106: [],\n",
       " 107: [],\n",
       " 108: [],\n",
       " 109: [],\n",
       " 110: [],\n",
       " 111: [],\n",
       " 112: [],\n",
       " 113: [],\n",
       " 114: [],\n",
       " 115: [],\n",
       " 116: [],\n",
       " 117: [],\n",
       " 118: [],\n",
       " 119: [],\n",
       " 120: [],\n",
       " 121: [],\n",
       " 122: [],\n",
       " 123: [],\n",
       " 124: [],\n",
       " 125: [],\n",
       " 126: [],\n",
       " 127: [],\n",
       " 128: [],\n",
       " 129: [],\n",
       " 130: [],\n",
       " 131: [],\n",
       " 132: [],\n",
       " 133: [],\n",
       " 134: [],\n",
       " 135: [],\n",
       " 136: [],\n",
       " 137: [],\n",
       " 138: [],\n",
       " 139: [],\n",
       " 140: [],\n",
       " 141: [],\n",
       " 142: [],\n",
       " 143: [],\n",
       " 144: [],\n",
       " 145: [],\n",
       " 146: [],\n",
       " 147: [],\n",
       " 148: [],\n",
       " 149: [],\n",
       " 150: [],\n",
       " 151: [],\n",
       " 152: [],\n",
       " 153: [],\n",
       " 154: [],\n",
       " 155: [],\n",
       " 156: [],\n",
       " 157: [],\n",
       " 158: [],\n",
       " 159: [],\n",
       " 160: [],\n",
       " 161: [],\n",
       " 162: [],\n",
       " 163: [],\n",
       " 164: [],\n",
       " 165: [],\n",
       " 166: [],\n",
       " 167: [],\n",
       " 168: [],\n",
       " 169: [],\n",
       " 170: [],\n",
       " 171: [],\n",
       " 172: [],\n",
       " 173: [],\n",
       " 174: [],\n",
       " 175: [],\n",
       " 176: [],\n",
       " 177: [],\n",
       " 178: [],\n",
       " 179: [],\n",
       " 180: [],\n",
       " 181: [],\n",
       " 182: [],\n",
       " 183: [],\n",
       " 184: [],\n",
       " 185: [],\n",
       " 186: [],\n",
       " 187: [],\n",
       " 188: [],\n",
       " 189: [],\n",
       " 190: [],\n",
       " 191: [],\n",
       " 192: [],\n",
       " 193: [],\n",
       " 194: [],\n",
       " 195: [],\n",
       " 196: [],\n",
       " 197: [],\n",
       " 198: [],\n",
       " 199: [],\n",
       " 200: [],\n",
       " 201: [],\n",
       " 202: [],\n",
       " 203: [],\n",
       " 204: [],\n",
       " 205: [],\n",
       " 206: [],\n",
       " 207: [],\n",
       " 208: [],\n",
       " 209: [],\n",
       " 210: [],\n",
       " 211: [],\n",
       " 212: [],\n",
       " 213: [],\n",
       " 214: [],\n",
       " 215: [],\n",
       " 216: [],\n",
       " 217: [],\n",
       " 218: [],\n",
       " 219: [],\n",
       " 220: [],\n",
       " 221: [],\n",
       " 222: [],\n",
       " 223: [],\n",
       " 224: [],\n",
       " 225: [],\n",
       " 226: [],\n",
       " 227: [],\n",
       " 228: [],\n",
       " 229: [],\n",
       " 230: [],\n",
       " 231: [],\n",
       " 232: [],\n",
       " 233: [],\n",
       " 234: [],\n",
       " 235: [],\n",
       " 236: [],\n",
       " 237: [],\n",
       " 238: [],\n",
       " 239: [],\n",
       " 240: [],\n",
       " 241: [],\n",
       " 242: [],\n",
       " 243: [],\n",
       " 244: [],\n",
       " 245: [],\n",
       " 246: [],\n",
       " 247: [],\n",
       " 248: [],\n",
       " 249: [],\n",
       " 250: [],\n",
       " 251: [],\n",
       " 252: [],\n",
       " 253: [],\n",
       " 254: [],\n",
       " 255: [],\n",
       " 256: [],\n",
       " 257: [],\n",
       " 258: [],\n",
       " 259: [],\n",
       " 260: [],\n",
       " 261: [],\n",
       " 262: [],\n",
       " 263: [],\n",
       " 264: [],\n",
       " 265: [],\n",
       " 266: [],\n",
       " 267: [],\n",
       " 268: [],\n",
       " 269: [],\n",
       " 270: [],\n",
       " 271: [],\n",
       " 272: [],\n",
       " 273: [],\n",
       " 274: [],\n",
       " 275: [],\n",
       " 276: [],\n",
       " 277: [],\n",
       " 278: [],\n",
       " 279: [],\n",
       " 280: [],\n",
       " 281: [],\n",
       " 282: [],\n",
       " 283: [],\n",
       " 284: [],\n",
       " 285: [],\n",
       " 286: [],\n",
       " 287: [],\n",
       " 288: [],\n",
       " 289: [],\n",
       " 290: [],\n",
       " 291: [],\n",
       " 292: [],\n",
       " 293: [],\n",
       " 294: [],\n",
       " 295: [],\n",
       " 296: [],\n",
       " 297: [],\n",
       " 298: [],\n",
       " 299: [],\n",
       " 300: [],\n",
       " 301: [],\n",
       " 302: [],\n",
       " 303: [],\n",
       " 304: [],\n",
       " 305: [],\n",
       " 306: [],\n",
       " 307: [],\n",
       " 308: [],\n",
       " 309: [],\n",
       " 310: [],\n",
       " 311: [],\n",
       " 312: [],\n",
       " 313: [],\n",
       " 314: [],\n",
       " 315: [],\n",
       " 316: [],\n",
       " 317: [],\n",
       " 318: [],\n",
       " 319: [],\n",
       " 320: [],\n",
       " 321: [],\n",
       " 322: [],\n",
       " 323: [],\n",
       " 324: [],\n",
       " 325: [],\n",
       " 326: [],\n",
       " 327: [],\n",
       " 328: [],\n",
       " 329: [],\n",
       " 330: [],\n",
       " 331: [],\n",
       " 332: [],\n",
       " 333: [],\n",
       " 334: [],\n",
       " 335: [],\n",
       " 336: [],\n",
       " 337: [],\n",
       " 338: [],\n",
       " 339: [],\n",
       " 340: [],\n",
       " 341: [],\n",
       " 342: [],\n",
       " 343: [],\n",
       " 344: [],\n",
       " 345: [],\n",
       " 346: [],\n",
       " 347: [],\n",
       " 348: [],\n",
       " 349: [],\n",
       " 350: [],\n",
       " 351: [],\n",
       " 352: [],\n",
       " 353: [],\n",
       " 354: [],\n",
       " 355: [],\n",
       " 356: [],\n",
       " 357: [],\n",
       " 358: [],\n",
       " 359: [],\n",
       " 360: [],\n",
       " 361: [],\n",
       " 362: [],\n",
       " 363: [],\n",
       " 364: [],\n",
       " 365: [],\n",
       " 366: [],\n",
       " 367: [],\n",
       " 368: [],\n",
       " 369: [],\n",
       " 370: [],\n",
       " 371: [],\n",
       " 372: [],\n",
       " 373: [],\n",
       " 374: [],\n",
       " 375: [],\n",
       " 376: [],\n",
       " 377: [],\n",
       " 378: [],\n",
       " 379: [],\n",
       " 380: [],\n",
       " 381: [],\n",
       " 382: [],\n",
       " 383: [],\n",
       " 384: [],\n",
       " 385: [],\n",
       " 386: [],\n",
       " 387: [],\n",
       " 388: [],\n",
       " 389: [],\n",
       " 390: [],\n",
       " 391: [],\n",
       " 392: [],\n",
       " 393: [],\n",
       " 394: [],\n",
       " 395: [],\n",
       " 396: [],\n",
       " 397: [],\n",
       " 398: [],\n",
       " 399: [],\n",
       " 400: [],\n",
       " 401: [],\n",
       " 402: [],\n",
       " 403: [],\n",
       " 404: [],\n",
       " 405: [],\n",
       " 406: [],\n",
       " 407: [],\n",
       " 408: [],\n",
       " 409: [],\n",
       " 410: [],\n",
       " 411: [],\n",
       " 412: [],\n",
       " 413: [],\n",
       " 414: [],\n",
       " 415: [],\n",
       " 416: [],\n",
       " 417: [],\n",
       " 418: [],\n",
       " 419: [],\n",
       " 420: [],\n",
       " 421: [],\n",
       " 422: [],\n",
       " 423: [],\n",
       " 424: [],\n",
       " 425: [],\n",
       " 426: [],\n",
       " 427: [],\n",
       " 428: [],\n",
       " 429: [],\n",
       " 430: [],\n",
       " 431: [],\n",
       " 432: [],\n",
       " 433: [],\n",
       " 434: [],\n",
       " 435: [],\n",
       " 436: [],\n",
       " 437: [],\n",
       " 438: [],\n",
       " 439: [],\n",
       " 440: [],\n",
       " 441: [],\n",
       " 442: [],\n",
       " 443: [],\n",
       " 444: [],\n",
       " 445: [],\n",
       " 446: [],\n",
       " 447: [],\n",
       " 448: [],\n",
       " 449: [],\n",
       " 450: [],\n",
       " 451: [],\n",
       " 452: [],\n",
       " 453: [],\n",
       " 454: [],\n",
       " 455: [],\n",
       " 456: [],\n",
       " 457: [],\n",
       " 458: [],\n",
       " 459: [],\n",
       " 460: [],\n",
       " 461: [],\n",
       " 462: [],\n",
       " 463: [],\n",
       " 464: [],\n",
       " 465: [],\n",
       " 466: [],\n",
       " 467: [],\n",
       " 468: [],\n",
       " 469: [],\n",
       " 470: [],\n",
       " 471: [],\n",
       " 472: [],\n",
       " 473: [],\n",
       " 474: [],\n",
       " 475: [],\n",
       " 476: [],\n",
       " 477: [],\n",
       " 478: [],\n",
       " 479: [],\n",
       " 480: [],\n",
       " 481: [],\n",
       " 482: [],\n",
       " 483: [],\n",
       " 484: [],\n",
       " 485: [],\n",
       " 486: [],\n",
       " 487: [],\n",
       " 488: [],\n",
       " 489: [],\n",
       " 490: [],\n",
       " 491: [],\n",
       " 492: [],\n",
       " 493: [],\n",
       " 494: [],\n",
       " 495: [],\n",
       " 496: [],\n",
       " 497: [],\n",
       " 498: [],\n",
       " 499: [],\n",
       " 500: [],\n",
       " 501: [],\n",
       " 502: [],\n",
       " 503: [],\n",
       " 504: [],\n",
       " 505: [],\n",
       " 506: [],\n",
       " 507: [],\n",
       " 508: [],\n",
       " 509: [],\n",
       " 510: [],\n",
       " 511: [],\n",
       " 512: [],\n",
       " 513: [],\n",
       " 514: [],\n",
       " 515: [],\n",
       " 516: [],\n",
       " 517: [],\n",
       " 518: [],\n",
       " 519: [],\n",
       " 520: [],\n",
       " 521: [],\n",
       " 522: [],\n",
       " 523: [],\n",
       " 524: [],\n",
       " 525: [],\n",
       " 526: [],\n",
       " 527: [],\n",
       " 528: [],\n",
       " 529: [],\n",
       " 530: [],\n",
       " 531: [],\n",
       " 532: [],\n",
       " 533: [],\n",
       " 534: [],\n",
       " 535: [],\n",
       " 536: [],\n",
       " 537: [],\n",
       " 538: [],\n",
       " 539: [],\n",
       " 540: [],\n",
       " 541: [],\n",
       " 542: [],\n",
       " 543: [],\n",
       " 544: [],\n",
       " 545: [],\n",
       " 546: [],\n",
       " 547: [],\n",
       " 548: [],\n",
       " 549: [],\n",
       " 550: [],\n",
       " 551: [],\n",
       " 552: [],\n",
       " 553: [],\n",
       " 554: [],\n",
       " 555: [],\n",
       " 556: [],\n",
       " 557: [],\n",
       " 558: [],\n",
       " 559: [],\n",
       " 560: [],\n",
       " 561: [],\n",
       " 562: [],\n",
       " 563: [],\n",
       " 564: [],\n",
       " 565: [],\n",
       " 566: [],\n",
       " 567: [],\n",
       " 568: [],\n",
       " 569: [],\n",
       " 570: [],\n",
       " 571: [],\n",
       " 572: [],\n",
       " 573: [],\n",
       " 574: [],\n",
       " 575: [],\n",
       " 576: [],\n",
       " 577: [],\n",
       " 578: [],\n",
       " 579: [],\n",
       " 580: [],\n",
       " 581: [],\n",
       " 582: [],\n",
       " 583: [],\n",
       " 584: [],\n",
       " 585: [],\n",
       " 586: [],\n",
       " 587: [],\n",
       " 588: [],\n",
       " 589: [],\n",
       " 590: [],\n",
       " 591: [],\n",
       " 592: [],\n",
       " 593: [],\n",
       " 594: [],\n",
       " 595: [],\n",
       " 596: [],\n",
       " 597: [],\n",
       " 598: [],\n",
       " 599: [],\n",
       " 600: [],\n",
       " 601: [],\n",
       " 602: [],\n",
       " 603: [],\n",
       " 604: [],\n",
       " 605: [],\n",
       " 606: [],\n",
       " 607: [],\n",
       " 608: [],\n",
       " 609: [],\n",
       " 610: [],\n",
       " 611: [],\n",
       " 612: [],\n",
       " 613: [],\n",
       " 614: [],\n",
       " 615: [],\n",
       " 616: [],\n",
       " 617: [],\n",
       " 618: [],\n",
       " 619: [],\n",
       " 620: [],\n",
       " 621: [],\n",
       " 622: [],\n",
       " 623: [],\n",
       " 624: [],\n",
       " 625: [],\n",
       " 626: [],\n",
       " 627: [],\n",
       " 628: [],\n",
       " 629: [],\n",
       " 630: [],\n",
       " 631: [],\n",
       " 632: [],\n",
       " 633: [],\n",
       " 634: [],\n",
       " 635: [],\n",
       " 636: [],\n",
       " 637: [],\n",
       " 638: [],\n",
       " 639: [],\n",
       " 640: [],\n",
       " 641: [],\n",
       " 642: [],\n",
       " 643: [],\n",
       " 644: [],\n",
       " 645: [],\n",
       " 646: [],\n",
       " 647: [],\n",
       " 648: [],\n",
       " 649: [],\n",
       " 650: [],\n",
       " 651: [],\n",
       " 652: [],\n",
       " 653: [],\n",
       " 654: [],\n",
       " 655: [],\n",
       " 656: [],\n",
       " 657: [],\n",
       " 658: [],\n",
       " 659: [],\n",
       " 660: [],\n",
       " 661: [],\n",
       " 662: [],\n",
       " 663: [],\n",
       " 664: [],\n",
       " 665: [],\n",
       " 666: [],\n",
       " 667: [],\n",
       " 668: [],\n",
       " 669: [],\n",
       " 670: [],\n",
       " 671: [],\n",
       " 672: [],\n",
       " 673: [],\n",
       " 674: [],\n",
       " 675: [],\n",
       " 676: [],\n",
       " 677: [],\n",
       " 678: [],\n",
       " 679: [],\n",
       " 680: [],\n",
       " 681: [],\n",
       " 682: [],\n",
       " 683: [],\n",
       " 684: [],\n",
       " 685: [],\n",
       " 686: [],\n",
       " 687: [],\n",
       " 688: [],\n",
       " 689: [],\n",
       " 690: [],\n",
       " 691: [],\n",
       " 692: [],\n",
       " 693: [],\n",
       " 694: [],\n",
       " 695: [],\n",
       " 696: [],\n",
       " 697: [],\n",
       " 698: [],\n",
       " 699: [],\n",
       " 700: [],\n",
       " 701: [],\n",
       " 702: [],\n",
       " 703: [],\n",
       " 704: [],\n",
       " 705: [],\n",
       " 706: [],\n",
       " 707: [],\n",
       " 708: [],\n",
       " 709: [],\n",
       " 710: [],\n",
       " 711: [],\n",
       " 712: [],\n",
       " 713: [],\n",
       " 714: [],\n",
       " 715: [],\n",
       " 716: [],\n",
       " 717: [],\n",
       " 718: [],\n",
       " 719: [],\n",
       " 720: [],\n",
       " 721: [],\n",
       " 722: [],\n",
       " 723: [],\n",
       " 724: [],\n",
       " 725: [],\n",
       " 726: [],\n",
       " 727: [],\n",
       " 728: [],\n",
       " 729: [],\n",
       " 730: [],\n",
       " 731: [],\n",
       " 732: [],\n",
       " 733: [],\n",
       " 734: [],\n",
       " 735: [],\n",
       " 736: [],\n",
       " 737: [],\n",
       " 738: [],\n",
       " 739: [],\n",
       " 740: [],\n",
       " 741: [],\n",
       " 742: [],\n",
       " 743: [],\n",
       " 744: [],\n",
       " 745: [],\n",
       " 746: [],\n",
       " 747: [],\n",
       " 748: [],\n",
       " 749: [],\n",
       " 750: [],\n",
       " 751: [],\n",
       " 752: [],\n",
       " 753: [],\n",
       " 754: [],\n",
       " 755: [],\n",
       " 756: [],\n",
       " 757: [],\n",
       " 758: [],\n",
       " 759: [],\n",
       " 760: [],\n",
       " 761: [],\n",
       " 762: [],\n",
       " 763: [],\n",
       " 764: [],\n",
       " 765: []}"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def template_no9():\n",
    "    #解决“出了哪些”的问题\n",
    "    template = \"(.*)家？\"\n",
    "    count=0\n",
    "    result_dict={}\n",
    "\n",
    "    for i in predata:\n",
    "        q = predata[i]['question']\n",
    "        result_dict[i]=[]\n",
    "        match_obj = re.match(template, q)\n",
    "        if match_obj:\n",
    "            print(i,match_obj.group().lower())\n",
    "            e1 = match_obj.group(1).lower()\n",
    "\n",
    "            #查询库\n",
    "            session = driver.session()\n",
    "            cql = \"match (a:Entity)-[b:Relation]-(c:Entity) \\\n",
    "                        where a.name=$name and b.name='<股票代码>'  return c.name\"\n",
    "\n",
    "            result = session.run(cql,name='<'+e1+'>')\n",
    "            for x in result:\n",
    "                print(x['c.name'])\n",
    "                result_dict[i].append(x['c.name'])\n",
    "\n",
    "            count+=1\n",
    "    print('此类问题所占比例为：'+str(100*count/len(predata)), str(count)+'/'+str(len(predata)))\n",
    "    return result_dict\n",
    "template_no9()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "def write2file(source,target,dic):\n",
    "    source = open(source,'r',encoding='utf-8').readlines()\n",
    "    saveto = open(target,'w',encoding='utf-8')\n",
    "    for i in range(len(source)):\n",
    "        if dic[i] !=[]:\n",
    "            saveto.write('\\t'.join(dic[i])+'\\n')\n",
    "        else:\n",
    "            saveto.write(source[i])\n",
    "    saveto.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "216 北京大学 作家\n",
      "216 北京大学 作家_（汉语词语）\n",
      "<余中先>\n",
      "<杨松河>\n",
      "<常聪>\n",
      "<桐华>\n",
      "<夏笳>\n",
      "<李华亭_（中国当代作家）>\n",
      "<骆漠>\n",
      "<胡兰波>\n",
      "<项小米>\n",
      "<儒帅哲师>\n",
      "<刘大军_（北京某文化发展有限公司副总经理）>\n",
      "<顾随>\n",
      "<杜染>\n",
      "<倪厚玉>\n",
      "<史杰鹏>\n",
      "<王蓬_（陕西省作家协会副主席）>\n",
      "<柳鸣九>\n",
      "<后山>\n",
      "<白崇义>\n",
      "<黄培佳>\n",
      "<李翊云>\n",
      "<左泓>\n",
      "<刘震云_（中国内地作家）>\n",
      "<马自力>\n",
      "<张志春_（易学家）>\n",
      "<张承志_（中国著名作家，红卫兵创始人之一）>\n",
      "<白榕_（中国内地作家）>\n",
      "<石丛>\n",
      "<查建英>\n",
      "<戈悟觉>\n",
      "<赵曙光_（中国内地作家）>\n",
      "<黄蓓佳>\n",
      "<冼宁_（中国现当代作家）>\n",
      "<赵遐秋>\n",
      "<废名_（20世纪著名作家、学者）>\n",
      "<胡又天>\n",
      "<陈楸帆>\n",
      "<徐訏>\n",
      "<沈威风>\n",
      "<王实味>\n",
      "<许君远>\n",
      "<娇羞胡萝卜>\n",
      "<王沂暖>\n",
      "<马昌仪>\n",
      "<马嘶_（原唐山市文联主席）>\n",
      "<马宪泉>\n",
      "<杜承南>\n",
      "<董志谋>\n",
      "<郑恩波>\n",
      "<张天翼_（中国现代著名作家）>\n",
      "<陈炜谟>\n",
      "<金涛_（中国科普作家协会副理事长）>\n",
      "<陆侃如>\n",
      "<西川_（中国当代诗人）>\n",
      "<悠世>\n",
      "<张伯江>\n",
      "<俞平伯>\n",
      "<刘海影>\n",
      "<刘咏_（中国当代作家）>\n",
      "<韩耀成>\n",
      "<树下野狐>\n",
      "<贺捷生>\n",
      "220 哈佛大学 物理学家\n",
      "220 哈佛大学 物理学家_（探索、研究物理学的科学家）\n",
      "<罗伯特·奥本海默>\n",
      "<叶企孙>\n",
      "<戴维·波利策>\n",
      "<珀西·布里奇曼>\n",
      "<西奥多·赖曼>\n",
      "<胡刚复>\n",
      "<菲利普·沃伦·安德森>\n",
      "248 清华大学 化学家\n",
      "248 清华大学 化学家\n",
      "<王晓业>\n",
      "<庄亚辉>\n",
      "<徐又一>\n",
      "<季鸣时>\n",
      "<金道森>\n",
      "252 重庆大学 企业家\n",
      "252 重庆大学 企业家\n",
      "<任正非>\n",
      "<董德福_（云狐时代集团董事长）>\n",
      "256 北京大学 天文学家\n",
      "256 北京大学 天文学家\n",
      "<陈建生_（中国信息经济学会理事）>\n",
      "291 浙江大学 科学家\n",
      "291 浙江大学 科学家_（从事科学研究的人群）\n",
      "<吴剑锋_（中国科学院理化技术研究所副所长）>\n",
      "<林励吾>\n",
      "<谭其猛>\n",
      "<吕鸿声>\n",
      "<罗安_（中国工程院院士）>\n",
      "<李志坚_（中国科学院院士）>\n",
      "<李光林_（中国科学院深圳先进技术研究院研究员）>\n",
      "<文学军>\n",
      "294 北京大学 科学家\n",
      "294 北京大学 科学家_（从事科学研究的人群）\n",
      "<万元熙>\n",
      "<王阿莲>\n",
      "<程和平_（中国科学院院士）>\n",
      "<郑晓瑛>\n",
      "<王义遒>\n",
      "<黄荣辉>\n",
      "<郁彬>\n",
      "<唐剑武>\n",
      "<王阳元>\n",
      "<陈和生_（科学物理学家）>\n",
      "<邹冰松>\n",
      "<赵学搏>\n",
      "296 武汉大学 天文学家\n",
      "296 武汉大学 天文学家\n",
      "<张家铝>\n",
      "298 北京大学 经济学家\n",
      "298 北京大学 经济学家_（拥有原创的经济学基础理论的经济学人）\n",
      "<樊弘>\n",
      "<丁志杰>\n",
      "<麻勇爱>\n",
      "<朱海斌_（摩根大通中国首席经济学家）>\n",
      "<朱偰>\n",
      "<王则柯>\n",
      "<高善文>\n",
      "<王梦奎>\n",
      "<何学彦>\n",
      "<程志强_（北京大学兼职教授、博士生导师）>\n",
      "<梁小民>\n",
      "<厉以宁>\n",
      "<刘海影>\n",
      "305 吉林大学 科学家\n",
      "305 吉林大学 科学家_（从事科学研究的人群）\n",
      "<郑永真>\n",
      "<于洋_（辽宁医学院食品科学与工程学院教授）>\n",
      "<怀进鹏>\n",
      "<侯蓝田>\n",
      "319 浙江大学 导演\n",
      "319 浙江大学 导演\n",
      "<朱卫_（影视剧编剧、导演、制作人）>\n",
      "<陈骁强>\n",
      "<马侃_（电影制片人、导演）>\n",
      "326 武汉大学 企业家\n",
      "326 武汉大学 企业家\n",
      "<初殿松>\n",
      "<郑贵林>\n",
      "<石江泳>\n",
      "<陈东升_（泰康人寿保险股份有限公司董事长）>\n",
      "<阎志_（卓尔控股有限公司董事长）>\n",
      "<雷军_（IT企业家、小米创始人）>\n",
      "<汪越_（双冠王网络贵人学创始人）>\n",
      "<吕俊_（企业家）>\n",
      "<朱黎>\n",
      "<王小村>\n",
      "<张世学>\n",
      "<张贻明>\n",
      "<谭树海>\n",
      "<陈天生_（中国十大杰出青年）>\n",
      "329 清华大学 哲学家\n",
      "329 清华大学 哲学家_（基础含义）\n",
      "<金岳霖>\n",
      "<沈有鼎>\n",
      "<汤用彤>\n",
      "<贺麟_（“新心学”创建者）>\n",
      "<周辅成>\n",
      "336 清华大学 天文学家\n",
      "336 清华大学 天文学家\n",
      "<林家翘>\n",
      "345 北京大学 物理学家\n",
      "345 北京大学 物理学家_（探索、研究物理学的科学家）\n",
      "<李淼_（中山大学天文与空间科学研究院院长）>\n",
      "<赵广增>\n",
      "<甘子钊>\n",
      "<马大猷>\n",
      "<郭永怀>\n",
      "<吴咏时>\n",
      "<张恩厚>\n",
      "<曾谨言>\n",
      "<岳劼恒>\n",
      "<向守平>\n",
      "<吴杭生>\n",
      "346 北京大学 思想家\n",
      "346 北京大学 思想家_（词语）\n",
      "<罗家伦_（中国近代教育家）>\n",
      "357 四川大学 作家\n",
      "357 四川大学 作家_（汉语词语）\n",
      "<徐甲子>\n",
      "<挚谊>\n",
      "<宁航一>\n",
      "<熊盛荣>\n",
      "<熊复>\n",
      "<小鸟凶猛>\n",
      "<凤歌_（武侠作家）>\n",
      "<刘燕君>\n",
      "<王樟生>\n",
      "<松笔>\n",
      "<童恩正>\n",
      "<阿缺_（青年作家）>\n",
      "<靡宝>\n",
      "<颜歌>\n",
      "<何顺安>\n",
      "<易丹_（《誓言今生》编剧，四川大学教师）>\n",
      "372 四川大学 企业家\n",
      "372 四川大学 企业家\n",
      "<周冬雨聂圣哲>\n",
      "<蒋涛_（CSDN网站创始人）>\n",
      "<张杰贤>\n",
      "<刘庆新_（成都被杀害亿万富豪）>\n",
      "<蒲发春>\n",
      "<王国成_（贝尔化工集团有限公司董事长、总裁）>\n",
      "<李小麟>\n",
      "<杨晓春_（企业家）>\n",
      "383 北京大学 生物学家\n",
      "383 北京大学 生物学家\n",
      "<周建人>\n",
      "<秉志>\n",
      "<潘文石>\n",
      "<钱煦>\n",
      "395 东南大学 数学家\n",
      "395 东南大学 数学家_（数学家（世界著名数学家））\n",
      "<坂内英一>\n",
      "<金田康正>\n",
      "<谷山丰>\n",
      "397 吉林大学 企业家\n",
      "397 吉林大学 企业家\n",
      "<王梓木_（华泰保险董事长，敬一丹丈夫）>\n",
      "<马蔚华>\n",
      "此类问题所占比例为：2.741514360313316 21/766\n",
      "667 600570 发行总股本\n",
      "\"6.18亿\"\n",
      "668 600570 流通A股\n",
      "\"6.18亿\"\n",
      "此类问题所占比例为：0.26109660574412535 2/766\n",
      "664 恒生电子股份有限公司\n",
      "\"硕士\"\n",
      "691 华泰证券\n",
      "\"本科\"\n",
      "693 光大证券\n",
      "\"博士\"\n",
      "695 海通证券\n",
      "\"硕士\"\n",
      "718 京东方A\n",
      "<工学硕士>\n",
      "此类问题所占比例为：0.6527415143603134 5/766\n",
      "474 大连\n",
      "<大商所>\n",
      "673 上海\n",
      "<上海期货交易所>\n",
      "674 郑州\n",
      "<郑州商品交易所>\n",
      "<郑商所>\n",
      "675 大连\n",
      "<大商所>\n",
      "676 魔都\n",
      "<上海期货交易所>\n",
      "此类问题所占比例为：0.6527415143603134 5/766\n",
      "457 国内\n",
      "<大商所>\n",
      "<上期所>\n",
      "<郑商所>\n",
      "458 上海\n",
      "<上期所>\n",
      "<上期所>\n",
      "459 中国\n",
      "<大商所>\n",
      "<上期所>\n",
      "<郑商所>\n",
      "460 郑州\n",
      "<郑商所>\n",
      "<郑商所>\n",
      "461 大连\n",
      "<大商所>\n",
      "<大商所>\n",
      "此类问题所占比例为：0.6527415143603134 5/766\n",
      "679 郑商所上市的农产品期货有什么\n",
      "<棉纱>\n",
      "<苹果>\n",
      "<棉花>\n",
      "<菜籽油>\n",
      "<油菜籽>\n",
      "<强麦>\n",
      "<普麦>\n",
      "<晚籼稻>\n",
      "<白糖>\n",
      "<粳稻>\n",
      "<早籼稻>\n",
      "<菜籽粕>\n",
      "680 郑商所上市的非农产品期货有什么\n",
      "<硅铁>\n",
      "<动力煤>\n",
      "<甲醇>\n",
      "<玻璃>\n",
      "<PTA>\n",
      "<锰硅>\n",
      "681 上海期货交易所上市的期货品种中金属期货有什么\n",
      "<镍>\n",
      "<镍>\n",
      "<铜>\n",
      "<铜>\n",
      "<黄金>\n",
      "<锌>\n",
      "<锌>\n",
      "<锡>\n",
      "<锡>\n",
      "<铝>\n",
      "<铝>\n",
      "<螺纹钢>\n",
      "<螺纹钢>\n",
      "<热轧卷板>\n",
      "<铅>\n",
      "<铅>\n",
      "<线材>\n",
      "<线材>\n",
      "<白银>\n",
      "682 上海期货交易所上市的期货品种中能源化工期货有什么\n",
      "<天然橡胶>\n",
      "<燃料油>\n",
      "<沥青>\n",
      "<沥青>\n",
      "<纸浆>\n",
      "<原油>\n",
      "683 上海期货交易所上市的期货品种中衍生品期货有什么\n",
      "<铜期权>\n",
      "<天胶期权>\n",
      "此类问题所占比例为：0.6527415143603134 5/766\n",
      "419 平安银行的全称是什么？\n",
      "\"平安银行股份有限公司\"\n",
      "<平安银行股份有限公司>\n",
      "\"Ping An Bank Co., Ltd.\"\n",
      "<平安银行股份有限公司>\n",
      "448 大华股份的全称是什么\n",
      "<浙江大华技术股份有限公司>\n",
      "489 信和置业的全称是什么\n",
      "<Sino_Land_Co._Ltd.>\n",
      "<信和置业有限公司>\n",
      "510 00国债08的全称？\n",
      "\"2000年记账式(八期)国债\"\n",
      "511 丝绸转债的全称？\n",
      "\"吴江丝绸股份有限公司可转换公司债券\"\n",
      "556 lof的全称是什么？\n",
      "\"上市型开放式基金\"\n",
      "<南方中证500指数>\n",
      "617 福莱特的全称是什么？\n",
      "<福莱特玻璃集团股份有限公司>\n",
      "618 恒铭达的全称是什么？\n",
      "<苏州恒铭达电子科技股份有限公司>\n",
      "619 威尔药业的全称是什么？\n",
      "<南京威尔药业股份有限公司>\n",
      "620 华致酒行的全称是什么？\n",
      "\"华致酒行连锁管理股份有限公司\"\n",
      "<华致酒行>\n",
      "<华致酒行连锁管理股份有限公司>\n",
      "此类问题所占比例为：1.3054830287206267 10/766\n",
      "446 海泰发展的股票代码是多少\n",
      "\"600082\"\n",
      "477 大华股份的股票代码是多少？\n",
      "\"002236\"\n",
      "537 光大证券的股票代码是什么？\n",
      "\"601788\"\n",
      "588 阿里巴巴股票代码\n",
      "\"BABA\"\n",
      "596 小米科技有限责任公司股票代码是多少？\n",
      "\"1810\"\n",
      "611 奥美医疗的股票代码是多少？\n",
      "\"002950\"\n",
      "612 西安银行的股票代码是多少？\n",
      "\"600928\"\n",
      "613 华阳国际的股票代码是多少？\n",
      "\"002949\"\n",
      "614 威派格的股票代码是多少？\n",
      "\"603956\"\n",
      "615 七彩化学的股票代码是多少？\n",
      "\"300758\"\n",
      "616 立华股份的股票代码是多少？\n",
      "\"300761\"\n",
      "此类问题所占比例为：1.4360313315926894 11/766\n"
     ]
    }
   ],
   "source": [
    "write2file('result/3in1.txt','result/result1.txt',template_no1())\n",
    "write2file('result/result1.txt','result/result2.txt',template_no2())\n",
    "write2file('result/result2.txt','result/result3.txt',template_no3())\n",
    "write2file('result/result3.txt','result/result4.txt',template_no4())\n",
    "write2file('result/result4.txt','result/result5.txt',template_no5())\n",
    "write2file('result/result5.txt','result/result6.txt',template_no6())\n",
    "write2file('result/result6.txt','result/result7.txt',template_no7())\n",
    "write2file('result/result7.txt','result/result8.txt',template_no8())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['威尔药业', '0']]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "men2ent_dic['威尔药业']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
